<template>
	<view>
		<u-navbar title="物流管理" placeholder autoBack>
			<view class="flexright xiaohui" slot="right" @click="jumpurl('/pages/workbench/tianjiawl')">添加</view>
		</u-navbar>
		<view class="mainpadding2">
			<view class="flexcenter" v-if="!list.data.length">
				<view class="placeholderimage" style="margin-top: 100rpx;" ></view>
			</view>
			<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id">
				<view class="flexbetween">
					<view class="hei_text titletext bold">{{item.name}}</view>
					<view class="xiaolv" v-if="item.type==0">固定運費</view>
					<view class="xiaolv" v-if="item.type==1">免運費</view>
					<view class="xiaolv" v-if="item.type==2">免運費折扣</view>
				</view>
				<view class="huang_text main_size margin_top bold pdl" v-if="item.type==0">固定：${{item.money_g}}</view>
				<view class="huang_text main_size margin_top bold pdl" v-if="item.type==2">固定：${{item.money_g}}
					滿${{item.money_count}} = ${{item.money_jian}}</view>
				<view class="flexright margin_top">
					<view class="flexleft margin_right" @click="jumpurl(`/pages/workbench/tianjiawl?id=${item.id}`)">
						<u-icon name="edit-pen" color="#999" size="16"></u-icon>
						<view class="xiaohei">編輯</view>
					</view>
					<view class="flexleft" @click="remove(item.id)">
						<u-icon name="trash" color="#999" size="16"></u-icon>
						<view class="xiaohei">刪除</view>
					</view>
				</view>
			</view>
		</view>
		<u-modal :show="show" showCancelButton confirmColor="#ffb800" @cancel="show=false" @confirm="confirm" confirmText="確認" cancelText="取消">
			<view class="slot-content color_ling text_weight text">
				您確定要刪除該物流嗎？
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				shop_id: uni.getStorageSync("shop_id"),
				list: {
					data: []
				},
				id:"",//物流id
			}
		},
		onShow() {
			this.getList()
		},
		methods: {
			async getList() {
				let res = await this.http.request('/api/shop/listFreight', 'POST', {
					shop_id: this.shop_id
				})
				if (res.code == 1) {
					this.list.data = res.data
				} else if (res.code == 0) {
					// this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			jumpurl(url) {
				uni.navigateTo({
					url
				})
			},
			remove(id){ //刪除物流
				this.id = id
				this.show = true
			},
			async confirm() {
				let _this = this
				let res = await this.http.request('/api/shop/Freightdel', 'POST', {
					shop_id: this.shop_id,
					id: this.id
				})
				if (res.code == 1) {
					this.http.toast("刪除成功！")
					let index = this.list.data.findIndex(item => {
						return this.id == item.id
					})
					this.list.data.splice(index, 1)
				} else if (res.code == 0) {
					// this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
				this.show = false
			},
		}
	}
</script>

<style>

</style>